Integer and floats

You can make the following operations with integer and floats (i.e. real mumbers)

Operation Result
+ Sum
- Substraction
* Multiplication
/ Division
// Integer division
** Exponentiation

Some simple examples are


In [ ]:
4+2

In [ ]:
10-42

In [ ]:
4 * 4

In [ ]:
10/3

In [ ]:
10//3

In [ ]:
10**3

Exercise 1.1

Compute the number of seconds since the day you were born


In [ ]:

Complex numbers

It is also posible to use complex numbers. Instead of using $i$ for $\sqrt{-1}$ python uses j.


In [ ]:
1j**2

Some typical math operations

Very common mathematical operations, sucha as taking the logarithm, can only be used after importing the module math.

For instance:


In [ ]:
import math

In [ ]:
math.log(10) #natural logarithm

In [ ]:
math.log10(10) #base 10 logarith,

In [ ]:
math.sqrt(10) # square root

In [ ]:
math.exp(2) # exponential

Exercise 1.2

Compute the value for the golden ratio number $(1+\sqrt{5})/2$


In [ ]: